<template>
    <div class="content-center">
        <div class="content-cotainer border-box">
            <div class="content-breadcrumb">
                <el-breadcrumb separator="/" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">审计分析</el-breadcrumb-item>
                    <el-breadcrumb-item>审计工作底稿</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <el-row :gutter="15">
                <el-col :span=12>
                    <div class="audit-content">
                        <div class="centent-title">
                            <span>{{title}}</span>
                        </div>
                        <!-- 页面内容 -->
                        <div class="centent-inner" style="padding:10px;">
                            <el-form :model="dataForm" label-width="140px" size="small">
                              <el-row >
                                  <el-button type="primary" size="small" @click="save">保存</el-button>
                                  <el-button type="info" size="small" @click="copydraft">复制</el-button>
                                  <el-button type="primary" size="small">修订</el-button>
                              </el-row>
                              <el-row style="padding-top:10px;">
                                  <el-button type="primary" size="small">导出</el-button>
                                  <el-button type="primary" size="small">同步审计工作底稿</el-button>
                                  <el-button type="primary" size="small" @click="showDraftStatus">维护底稿状态</el-button>
                                  <el-button type="primary" size="small" @click="showDraftAnnotate">批注</el-button>
                              </el-row>

                                <el-form-item style="margin-top: 10px;" label="审计工作底稿名称：">
                                    <el-input v-model="dataForm.auditDraftNm" placeholder="请输入底稿名称"></el-input>
                                </el-form-item>
                                <el-form-item label="审计事项：">
                                    <el-select v-model="dataForm.auditItemDsc" placeholder="请选择审计事项" style="width: 100%">
                                        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item label="细分审计事项：">
                                    <el-input v-model="dataForm.auditItemDsc" placeholder="请输入细分审计事项"></el-input>
                                </el-form-item>
                                <el-form-item label="编制人：">
                                    <el-select v-model="dataForm.rcrdCrtpsnNm" placeholder="请输入编制人" style="width: 100%">
                                        <el-option v-for="item in peplist" :key="item.value" :label="item.label" :value="item.value">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item label="编制日期：">
                                    <el-date-picker style="width: 100%" v-model="dataForm.writeDt" placeholder="请选择编制日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date" size="small"></el-date-picker>
                                </el-form-item>
                                <el-form-item label="审计过程：">
                                    <el-input type="textarea" :rows="5" v-model="dataForm.auditProcDsc" placeholder="请输入审计过程"></el-input>
                                </el-form-item>
                                <el-form-item label="审计认定的事实摘要及审计结论：">
                                    <el-input type="textarea" :rows="5" v-model="dataForm.deterfactsDsc" placeholder="请输入审计认定的事实摘要及审计结论"></el-input>
                                </el-form-item>
                                <el-form-item label="备注：">
                                    <el-input type="textarea" :rows="3" v-model="dataForm.remark" placeholder="请输入备注"></el-input>
                                </el-form-item>
                            </el-form>
                        </div>
                    </div>

                </el-col>
                <el-col :span=12>
                    <div class="audit-content">
                        <div class="centent-title">
                            <span>{{title}}</span>
                        </div>
                        <!-- 页面内容 -->
                        <div class="centent-inner" style="padding:10px;">
                           <el-row>
                               <el-button type="primary" size="small">下载证据</el-button>
                               <el-button type="primary" size="small">上传证据</el-button>
                               <el-button type="primary" size="small">删除证据</el-button>
                               <el-button type="primary" size="small">新建审计证据</el-button>
                           </el-row>
                           <el-row style="padding-top:15px;">
                               <el-button type="primary" size="small" @click="showEvidenceData">关联审计证据</el-button>
                               <el-button type="primary" size="small" @click="showDocketData">关联审计取证单</el-button>
                           </el-row>
                            <el-table :data="data" style="margin-top: 10px;width: 100%;border-radius:1px;border-top-left-radius: 6px;border-top-right-radius: 6px;border-bottom-left-radius: 6px;border-bottom-right-radius: 6px;" border>
                                <el-table-column type="selection" width="50" align="center"></el-table-column>
                                <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
                                <el-table-column prop="b" label="证据名称" align="center"></el-table-column>
                                <el-table-column prop="c" label="描述" align="center"></el-table-column>
                                <el-table-column prop="d" label="编制人" align="center"></el-table-column>
                                <el-table-column prop="e" label="编制日期" align="center"></el-table-column>
                            </el-table>
                            <el-pagination style="margin-top: 10px;" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 50, 100]" :page-size="10" layout="total, sizes, prev, pager, next, jumper" :total="40">
                            </el-pagination>

                            <el-dialog :visible.sync="dialogAuditTableVisible" title="审计证据" width="80%" top="10vh">
                                <el-table :data="auditTableData"  @selection-change="selsChange" stripe>
                                    <el-table-column type="selection"></el-table-column>
                                    <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
                                    <el-table-column label="审计证据名称" prop="auditPrfNm" align="center">
                                    </el-table-column>
                                    <el-table-column prop="prfDesc" label="审计证据概述">
                                    </el-table-column>
                                    <el-table-column prop="fileName" label="附件名称">
                                    </el-table-column>
                                    <el-table-column prop="createDt" label="编制日期"></el-table-column>
                                    <el-table-column prop="writerNm" label="编制人">
                                    </el-table-column>
                                    <el-table-column prop="lcsCd" label="状态"></el-table-column>
                                </el-table>
                                <div slot="footer" class="dialog-footer">
                                    <el-button @click="dialogAuditTableVisible = false">取消</el-button>
                                    <el-button  type="primary" @click="relationEvidence()">确定</el-button>
                                </div>
                            </el-dialog>

                            <el-dialog :visible.sync="dialogDocketTableVisible" title="审计取证单" width="80%" top="10vh">
                                <el-table :data="docketTableData"  @selection-change="selectChange" stripe>
                                    <el-table-column fixed type="selection" width="50" ></el-table-column>
                                    <el-table-column type="index" label="序号" width="50" align="center" ></el-table-column>
                                    <el-table-column label="审计取证单名称" prop="auditEvdblNm" align="center" width="200px"></el-table-column>
                                    <el-table-column label="审计事项" prop="auditItemDsc" align="center" width="100px"></el-table-column>
                                    <el-table-column label="细分审计事项" prop="auditItemDsc" align="center" width="150px"> </el-table-column>
                                    <el-table-column label="审计事项摘要" prop="auditorMatterDsc" align="center" width="200px"></el-table-column>
                                    <el-table-column label="附件名称" prop="docNm" align="center" width="100px"></el-table-column>
                                    <el-table-column label="编制日期" prop="createDt" align="center" width="200px"></el-table-column>
                                    <el-table-column label="编制人" prop="rcrdCrtpsnNm" align="center" width="100px"></el-table-column>
                                </el-table>
                                <div slot="footer" class="dialog-footer">
                                    <el-button @click="dialogDocketTableVisible = false">取消</el-button>
                                    <el-button  type="primary" @click="relationDocket()">确定</el-button>
                                </div>
                            </el-dialog>

                            <el-dialog :visible.sync="dialogPermissionVisible" title="维护底稿状态" width="40%" top="10vh">
                                <el-form  :model="statusTemp"  label-width="100px">
                                    <el-form-item label="底稿状态"  >
                                        <el-select v-model="statusTemp.auditStatusDsc"  placeholder="请选择" style="width: 70%;">
                                            <el-option v-for="item in auditStatus" :key="item.value"
                                                       :label="item.label" :value="item.value">
                                            </el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-form>
                                <div slot="footer" class="dialog-footer">
                                    <el-button @click="dialogPermissionVisible = false">取消</el-button>
                                    <el-button  type="primary" @click="updateAuditStatusDsc(statusTemp.auditStatusDsc)">保存</el-button>
                                </div>
                            </el-dialog>

                            <el-dialog :visible.sync="dialogAnnotateDscVisible" title="修改批注" width="40%" top="10vh">
                                <el-form  :model="annotateTemp"  label-width="100px">
                                    <el-form-item label="批注：">
                                        <el-input type="textarea" :rows="3" v-model="annotateTemp.annotateDsc" placeholder="请输入批注"></el-input>
                                    </el-form-item>
                                </el-form>
                                <div slot="footer" class="dialog-footer">
                                    <el-button @click="dialogAnnotateDscVisible = false">取消</el-button>
                                    <el-button  type="primary" @click="updateAuditAnnotateDsc()">保存</el-button>
                                </div>
                            </el-dialog>
                        </div>
                    </div>
                </el-col>
            </el-row>

        </div>
    </div>
</template>

<script>
    import evidenceservice from '@/api/auditoperationApi/evidenceservice'
    import axios from 'axios'
    export default {
        data() {
            return {
                peplist: [{
                    value: '1',
                    label: '李丽'
                }, {
                    value: '2',
                    label: '张三'
                }, {
                    value: '3',
                    label: '李四'
                }],
                options: [{
                    value: '1',
                    label: '事项1'
                }, {
                    value: '2',
                    label: '事项2'
                }, {
                    value: '3',
                    label: '事项3'
                }],
                dialogAuditTableVisible: false,
                dialogDocketTableVisible: false,
                auditTableData: [],
                docketTableData: [],
                selectedlist: [],
                sels: [],
                dialogPermissionVisible: false,
                dialogAnnotateDscVisible: false,
                annotateTemp:{
                    annotateDsc: ''
                },
                statusTemp: {
                    auditStatusDsc: ''
                },
                auditStatus: [
                    {
                        value: '1',
                        label: '未阅'
                    }, {
                        value: '2',
                        label: '已阅'
                    }, {
                        value: '3',
                        label: '需修订'
                    }, {
                        value: '4',
                        label: '需重写'
                    }, {
                        value: '5',
                        label: '需修改'
                    }, {
                        value: '6',
                        label: '已同步'
                    }
                ],
                dataForm: {
                    auditDraftId: '',
                    auditDraftNm: '',
                    auditItemDsc: '',
                    rcrdCrtpsnNm: '',
                    writeDt: '',
                    auditProcDsc: '',
                    deterfactsDsc: '',
                    remark: ''
                },
                model: {
                    event: ''
                },
                data: [{
                    b: '某某公司税务缴纳',
                    c: '预算编制不细化',
                    d: '张毅',
                    e: '2019-8-16'
                }],
                currentPage: 1,
                title: '新建底稿'
            }
        },
        mounted() {
            if (this.$route.query.auditDraftId) {
                let auditDraftId = this.$route.query.auditDraftId
                this.getData(auditDraftId);
            }
        },
        methods: {
            save() {
                let params = this.dataForm;
                let type = this.$route.query.type;
                //debugger
                if(params.auditDraftId && type =='edit'){
                    axios.post(evidenceservice.baseUrl +'/auditWorkerDraft/updateWorkDraft', params)
                        .then(response => {
                            this.$message({
                                type: 'success',
                                message: response.data.obj
                            });
                            this.$router.push({
                                path: '/auditOperationPage/auditdraft'
                            })
                        }, err => {
                            //reject(err);
                        }).catch((error) => {
                        //reject(error)
                    })
                }else if(params.auditDraftId && type =='copy'){
                    params.type = 'copy';
                    axios.post(evidenceservice.baseUrl +'/auditWorkerDraft/addWorkDraft', params)
                        .then(response => {
                            this.$message({
                                type: 'success',
                                message: response.data.obj
                            });
                            this.$router.push({
                                path: '/auditOperationPage/auditdraft'
                            })
                        }, err => {
                            //reject(err);
                        }).catch((error) => {
                        //reject(error)
                    })
                }else if(!params.auditDraftId && type == null){
                    axios.post(evidenceservice.baseUrl +'/auditWorkerDraft/addWorkDraft', params)
                        .then(response => {
                            this.$message({
                                type: 'success',
                                message: response.data.obj
                            });
                            this.$router.push({
                                path: '/auditOperationPage/auditdraft'
                            })
                        }, err => {
                            //reject(err);
                        }).catch((error) => {
                        //reject(error)
                    })
                }
            },
            updateAuditStatusDsc(val){
                let ids= this.$route.query.auditDraftId;
                let param = this.statusTemp;
                param.ids = ids ;
                axios.post(evidenceservice.baseUrl +'/auditWorkerDraft/updateWorkDraftParam', param)
                    .then(response => {
                        this.$message({
                            type: 'success',
                            message: response.data.obj
                        });
                        this.dialogPermissionVisible = false
                        this.getData();
                    }, err => {
                    }).catch((error) => {
                })
            },

            updateAuditAnnotateDsc(){
                let ids= this.$route.query.auditDraftId;
                let param = this.annotateTemp;
                param.ids = ids ;
                axios.post(evidenceservice.baseUrl +'/auditWorkerDraft/updateWorkDraftParam', param)
                    .then(response => {
                        this.$message({
                            type: 'success',
                            message: response.data.obj
                        });
                        this.dialogAnnotateDscVisible = false
                        this.getData();
                    }, err => {
                    }).catch((error) => {
                })
            },

            showDraftStatus(){
                this.dialogPermissionVisible = true
            },

            showDraftAnnotate(){
                this.dialogAnnotateDscVisible = true
            },

            copydraft() {
                let auditDraftId = this.$route.query.auditDraftId
                this.$router.push({
                    name: 'auditdraftadd', query: {auditDraftId: auditDraftId,type:'copy'}
                })
            },

            showEvidenceData(){
                this.dialogAuditTableVisible = true;
                let info = {
                    nodeId :1
                }
                axios.post(evidenceservice.baseUrl +'/evidence/queryEvidence', info).then((response) => {
                    this.auditTableData = response.data
                }).catch((response) => {
                    console.log(response)
                })
            },

            showDocketData(){
                this.dialogDocketTableVisible = true;
                let info = {
                    /*nodeId :1*/
                }
                axios.post(evidenceservice.baseUrl +'/evidenceAuditEvdBl/findAuditEvdBlList', info).then((response) => {
                    this.docketTableData = response.data.obj
                }).catch((response) => {
                    console.log(response)
                })
            },

            selsChange (val) {
                this.sels = val
            },

            selectChange (val){
                this.selectedlist = val
            },

            relationEvidence(){
                if(this.sels.length > 0){
                    this.dialogAuditTableVisible = false;
                }else{
                    this.$message.warning('请勾选数据')
                }
            },

            relationDocket(){
                if(this.selectedlist.length > 0){
                    this.dialogDocketTableVisible = false;
                }else{
                    this.$message.warning('请勾选数据')
                }
            },

            getData (auditDraftId) {
                axios.post(evidenceservice.baseUrl +'/auditWorkerDraft/findWorkDraftList', {auditDraftId:auditDraftId})
                    .then(response => {
                        //resolve(response);
                        this.dataForm = response.data.obj[0];
                    }, err => {
                        //reject(err);
                    })
                    .catch((error) => {
                        //reject(error)
                    })
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
            },
        }
    }
</script>

<style lang="less" scoped>
    .content-cotainer {
        padding: 0 15px 15px 15px;
        height: 100%;
        overflow:scroll;
    }
</style>
